package com.pzb.web.controller.market;

import java.util.List;

import com.pzb.market.domain.MkDiscount;
import com.pzb.wechat.service.IWechatAppletService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pzb.common.annotation.Log;
import com.pzb.common.core.controller.BaseController;
import com.pzb.common.core.domain.AjaxResult;
import com.pzb.common.enums.BusinessType;
import com.pzb.market.domain.MkGroupbuying;
import com.pzb.market.service.IMkGroupbuyingService;
import com.pzb.common.utils.poi.ExcelUtil;
import com.pzb.common.core.page.TableDataInfo;

/**
 * 拼团管理Controller
 * 
 * @author Mr_Wu
 * @date 2021-12-22
 */
@RestController
@RequestMapping("/market/groupbuying")
public class MkGroupbuyingController extends BaseController
{
    @Autowired
    private IMkGroupbuyingService mkGroupbuyingService;
    @Autowired
    private IWechatAppletService wechatAppletService;

    /**
     * 查询拼团管理列表
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:list')")
    @GetMapping("/list")
    public TableDataInfo list(MkGroupbuying mkGroupbuying)
    {
        mkGroupbuying.setExtAppid(wechatAppletService.getExtAppid());
        startPage();
        List<MkGroupbuying> list = mkGroupbuyingService.selectMkGroupbuyingList(mkGroupbuying);
        return getDataTable(list);
    }

    /**
     * 查询拼团管理列表
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:list')")
    @GetMapping("/groupbuyList")
    public AjaxResult groupbuyList(MkGroupbuying mkGroupbuying)
    {
        mkGroupbuying.setExtAppid(wechatAppletService.getExtAppid());
        List<MkGroupbuying> list = mkGroupbuyingService.selectMkGroupbuyingList(mkGroupbuying);
        return AjaxResult.success(list);
    }


    /**
     * 获取拼团管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mkGroupbuyingService.selectMkGroupbuyingById(id));
    }

    /**
     * 新增拼团管理
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:add')")
    @Log(title = "拼团管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MkGroupbuying mkGroupbuying)
    {
        String extAppid = wechatAppletService.getExtAppid();
        if("1".equals(extAppid)){
            return AjaxResult.error("您还没有小程序!");
        }
        mkGroupbuying.setExtAppid(wechatAppletService.getExtAppid());
        return toAjax(mkGroupbuyingService.insertMkGroupbuying(mkGroupbuying));
    }

    /**
     * 修改拼团管理
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:edit')")
    @Log(title = "拼团管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MkGroupbuying mkGroupbuying)
    {
        return toAjax(mkGroupbuyingService.updateMkGroupbuying(mkGroupbuying));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:edit')")
    @Log(title = "拼团管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody MkGroupbuying mkGroupbuying)
    {
        return toAjax(mkGroupbuyingService.updateMkGroupbuying(mkGroupbuying));
    }

    /**
     * 删除拼团管理
     */
    @PreAuthorize("@ss.hasPermi('market:groupbuying:remove')")
    @Log(title = "拼团管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mkGroupbuyingService.deleteMkGroupbuyingByIds(ids));
    }
}
